home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Utilities / vim-5.1 / syntax / perl.vim < prev    next >
Encoding:
Text File  |  1998-02-14  |  11.2 KB  |  257 lines

  1. " Vim syntax file
  2. " Language:    Perl
  3. " Maintainer:    Sonia Heimann <niania@netsurf.org>
  4. " Last change:    1997 Dec 16
  5.  
  6. " Remove any old syntax stuff hanging around
  7. syn clear
  8.  
  9. "
  10. " Comments
  11. "
  12.  
  13. " First, treat the the #!/bin/perl
  14. syn match  perlSharpBang         "^#!.\+$"
  15. " All other # are comment, when at the beginning of a line or after a space
  16. " (avoid m## case ...)
  17. syn match  perlComment         "^#\([^!].*\)\=$\|[ \t]#.*" contains=perlTodo
  18.  
  19. "
  20. " POD documentation
  21. "
  22.  
  23. " POD starts with ^=head and ends with =cut
  24. " Set the variable "perl_embedded_pod" to use embedded POD syntax file.
  25.  
  26. if !exists("perl_embedded_pod")
  27.   syntax region perlPOD start=+^=head+ end=+=cut+
  28.   syn sync match perlSyncPOD grouphere perlPOD "^=head"
  29.   syn sync match perlSyncPOD groupthere NONE "^=cut"
  30. else
  31.   let b:embedded_pod = 1
  32.   source <sfile>:p:h/pod.vim
  33.   unlet b:embedded_pod
  34.  
  35.   syn region perlEmbeddedPod start="^=pod" start="^=head1" matchgroup=podCommand end="^=cut" contains=podCommand,podVerbatimLine,podSpecial,podFormat
  36.   syn sync match perlEmbeddedPod grouphere perlEmbeddedPod "^=pod"
  37.   syn sync match perlEmbeddedPod grouphere perlEmbeddedPod "^=head1"
  38.   syn sync match perlEmbeddedPod groupthere NONE "^=cut"
  39. endif
  40.  
  41. "
  42. " Includes
  43. "
  44. syn region  perlInclude     start=+^[ \t]*\<\(use\|require\)\>+ end=+;+he=e-1
  45.  
  46.  
  47. "
  48. " All keywords
  49. "
  50. syn keyword perlLabel                   case default
  51. syn keyword perlConditional             if elsif unless else switch eq ne gt lt ge le cmp not and or xor
  52. syn keyword perlRepeat                  while for foreach do until
  53. syn keyword perlOperator                defined undef and or not bless
  54. syn keyword perlControl                 BEGIN END
  55.  
  56. syn keyword perlStatementStorageClass   my local
  57. syn keyword perlStatementControl        goto return last next continue redo
  58. syn keyword perlStatementScalar         chomp chop chr crypt index lc lcfirst length ord pack reverse rindex sprintf substr uc ucfirst
  59. syn keyword perlStatementRegexp         pos quotemeta split study
  60. syn keyword perlStatementNumeric        abs atan2 cos exp hex int log oct rand sin sqrt srand
  61. syn keyword perlStatementList           splice unshift shift push pop split join reverse grep map qw sort unpack
  62. syn keyword perlStatementHash           each exists keys values
  63. syn keyword perlStatementIOfunc         binmode close closedir dbmclose dbmopen die eof fileno flock format getc print printf read readdir rewinddir seek seekdir select syscall sysopen sysread syswrite tell telldir truncate warn write
  64. syn keyword perlStatementFixedlength    pack vec
  65. syn keyword perlStatementFiles          chdir chmod chown chroot fcntl glob ioctl link lstat mkdir open opendir readlink rename rmdir stat symlink umask unlink utime
  66. syn keyword perlStatementFlow           caller die dump eval exit wantarray
  67. syn keyword perlStatementScope          import
  68. syn keyword perlStatementProc           alarm exec fork getpgrp getppid getpriority kill pipe qx setpgrp setpriority sleep system times wait waitpid
  69. syn keyword perlStatementSocket         accept bind connect getpeername getsockname getsockopt listen recv send setsockopt shutdown socket socketpair
  70. syn keyword perlStatementIPC            msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite
  71. syn keyword perlStatementNetwork        endprotoent endservent gethostbyaddr gethostbyname gethostent getnetbyaddr getnetbyname getnetent getprotobyname getprotobynumber getprotoent getservbyname getservbyport getservent sethostent setnetent setprotoent setservent
  72. syn keyword perlStatementTime           gmtime localtime time times
  73. syn keyword perlStatementMisc           print warn formline reset scalar new delete STDIN STDOUT STDERR
  74.  
  75. syn keyword perlTodo contained TODO TBD
  76.  
  77. "
  78. " Perl Identifiers.
  79. "
  80.  
  81. " Plain identifier:
  82. "   Scalar identifier: $foo
  83. "   Array identifier: @foo
  84. "   Array Length: $#foo
  85. "   Hash identifier: %foo
  86. "   Function identifier: &foo
  87. "   Reference dereferences: @$foo, %$$foo, &$foo, $$foo, ...
  88.  
  89. " We do not process complex things such as @{${"foo"}}. Too complicated, and
  90. " too slow. And what is after the -> is *not* considered as part of the
  91. " variable - there again, too complicated and too slow.
  92.  
  93. " Special variables first ($^A, ...)
  94. syn match  perlVarPlain "$^[A-Z]"
  95. " Special variables, continued ($|, $', ...)
  96. syn match  perlVarPlain "$[\\\"\[\]'&`+*.,;=%~^:!@$<>(0-9-]"
  97. " These variables are not recognized within matches.
  98. syn match perlVarNotInMatches "$[|)]"
  99. " This variable is not recognized within matches delimited by //.
  100. syn match perlVarSlash "$/"
  101.  
  102. " And plain identifiers
  103.  
  104. syn match perlPackageRef "[a-zA-Z_][a-zA-Z0-9_]*\>\('\|::\)" contained
  105.  
  106. " To highlight packages in variables as a scope reference - i.e. in $pack::var,
  107. " pack:: is a scope, just set "perl_want_scope_in_variables"
  108. " If you *want* complex things like @{${"foo"}} to be processed,
  109. " just set the variable "perl_extended_vars"...
  110.  
  111. if exists("perl_want_scope_in_variables")
  112.   syn match perlVarPlain   "\(\$#\|\$\+\|@\$*\|%\$*\|\&\$*\)[a-zA-Z_][a-zA-Z0-9_]*\(\(::\|'\)[a-zA-Z_][a-zA-Z0-9_]*\)*\>" contains=perlPackageRef nextgroup=perlVarMember
  113. else
  114.   syn match perlVarPlain   "\(\$#\|\$\+\|@\$*\|%\$*\|\&\$*\)[a-zA-Z_][a-zA-Z0-9_]*\(\(::\|'\)[a-zA-Z_][a-zA-Z0-9_]*\)*\>" nextgroup=perlVarMember
  115. endif
  116.  
  117. if exists("perl_extended_vars")
  118.   syn region perlVarPlain start="[@%\$]{" skip="\\}" end="}" contains=perlVarPlain,perlVarNotInMatches,perlVarSlash nextgroup=perlVarMember
  119.   syn region perlVarMember start="\(->\)\={" skip="\\}" end="}" contained contains=perlVarPlain,perlVarNotInMatches,perlVarSlash nextgroup=perlVarMember
  120.   syn region perlVarMember start="\(->\)\=\[" skip="\\]" end="]" contained contains=perlVarPlain,perlVarNotInMatches,perlVarSlash nextgroup=perlVarMember
  121. endif
  122.  
  123. "
  124. " String and Character constants
  125. "
  126.  
  127. " Highlight special characters (those which have a backslash) differently
  128. syn match   perlSpecial           contained "\\[0-9][0-9][0-9]\|\\."
  129. " "" String may contain variables
  130. syn match   perlCharacter         "'[^\\]'"
  131. syn match   perlSpecialCharacter  "'\\.'"
  132. syn match   perlSpecialCharacter  "'\\[0-9][0-9][0-9]'"
  133.  
  134. " Strings
  135. syn region  perlString            start=+"+  skip=+\\\\\|\\"+  end=+"+ contains=perlSpecial,perlVarPlain,perlVarNotInMatches,perlVarSlash
  136. " '' Strings may not contain anything
  137. syn region  perlStringUnexpanded  start=+'+  skip=+\\\\\|\\"+  end=+'+ contains=perlSpecial
  138. syn region  perlStringUnexpanded  start="qw("hs=s+2 skip="\\\\\|\\)" end=")" contains=perlSpecial
  139.  
  140. " Shell commands
  141. syn region  perlShellCommand            start=+`+  skip=+\\\\\|\\"+  end=+`+ contains=perlSpecial,perlVarPlain
  142.  
  143. " Numbers
  144. syn match  perlNumber          "-\=\<[0-9]\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
  145.  
  146. " Constructs such as print <<EOF [...] EOF
  147. syn region perlUntilEOF start=+<<\(["`]\=\)EOF\1+hs=s+2 end=+^EOF$+ contains=perlSpecial,perlVarPlain,perlVarNotInMatches,perlVarSlash
  148. syn region perlUntilEOF start=+<<'EOF'+hs=s+2 end=+^EOF$+ contains=perlSpecial
  149. " When vim supports it, try to use something as
  150. " syntax region perlUntilEOF start=+<<\(["`]\=\)\([a-zA-Z]\+\)\1+s+2 end=+^\2$+
  151. " to allow any keyword, not just EOF. The \2 in the end pattern refers of
  152. " course to the second group in the start pattern.
  153.  
  154. "
  155. " Perl regexps, second version, thanks to Michael Firestone
  156. "
  157.  
  158. " any qq## expression
  159. syn match perlQQ "\<q[qxw]\=\([^a-zA-Z0-9_ \t\n]\).*[^\\]\(\\\\\)*\1" contains=perlVarPlain, perlVarSlash
  160. " Any m## match
  161. syn match perlMatchAny "\<m\([^a-zA-Z0-9_ \t\n]\).*[^\\]\(\\\\\)*\1[xosmige]*" contains=perlVarPlain,perlVarSlash
  162. " Plain m// match
  163. syn match perlMatchAny "\<m/.*[^\\]\(\\\\\)*/[xosmige]*" contains=perlVarPlain
  164. " Any s### substitute
  165. " s/// is handled separately, since it can't contain $/ as a variable.
  166. syn match perlSubstitute "\<s\([^a-zA-Z0-9_ \t\n]\).\{-}[^\\]\(\\\\\)*\1.\{-}[^\\]\(\\\\\)*\1[xosmige]*" contains=perlVarPlain,perlVarSlash
  167. syn match perlSubstitute "\<\(s\|y\|tr\)/.\{-}[^\\]\(\\\\\)*/.\{-}[^\\]\(\\\\\)*/[xosmige]*" contains=perlVarPlain
  168. " Note that the above rules don't match substitutions with empty
  169. " replacement texts (like s/deleteme//); these rules cover those.
  170. syn match perlSubstitute "\<s\([^a-zA-Z0-9_ \t\n]\).\{-}[^\\]\(\\\\\)*\1\1[xosmige]*" contains=perlVarPlain,perlVarSlash
  171. syn match perlSubstitute "\<\(s\|y\|tr\)/.\{-}[^\\]\(\\\\\)*//[xosmige]*" contains=perlVarPlain
  172. " The classical // construct
  173. syn match perlMatch "/\(\\/\|[^/]\)*[^\\]\(\\\\\)*/[xosmige]*" contains=perlVarPlain
  174.  
  175. syn match perlClassDecl        "^[ \t]*package\>[^;]*"
  176.  
  177. syn match  perlLineSkip     "\\$"
  178.  
  179. "
  180. " Functions
  181. "
  182.  
  183. " find ^sub foo { . Only highlight foo.
  184. " Function is sub foo { , sub foo( , sub foo;
  185. " Sneaky:  Instead of terminating the region at a '(' (the start of a
  186. " prototype), contain the prototype in the region and give it no
  187. " highlighting; that way, things inside the prototype that look like
  188. " variables won't be highlighted as variables.
  189. syn region perlFunction start=+^[ \t]*sub[ \t]\++hs=e+1 end=+[;{]+me=s-1 contains=perlFunctionPrototype
  190. syn match perlFunctionPrototype "([^)]*)" contained
  191.  
  192. if !exists("did_perl_syntax_inits")
  193.   let did_perl_syntax_inits = 1
  194.   " The default methods for highlighting.  Can be overridden later
  195.   hi link perlSharpBang  PreProc
  196.   hi link perlLabel        Label
  197.   hi link perlConditional    Conditional
  198.   hi link perlRepeat        Repeat
  199.   hi link perlOperator        Operator
  200.   hi link perlList        perlStatement
  201.   hi link perlMisc        perlStatement
  202.   hi link perlVarPlain    perlIdentifier
  203.   hi link perlVarMember    perlIdentifier
  204.   hi link perlVarNotInMatches    perlIdentifier
  205.   hi link perlVarSlash    perlIdentifier
  206.   hi link perlQQ    perlString
  207.   hi link perlUntilEOF    perlString
  208.   hi link perlStringUnexpanded    perlString
  209.   hi link perlCharacter        Character
  210.   hi link perlSpecialCharacter    perlSpecial
  211.   hi link perlMatchAny perlMatch
  212.   hi link perlSubstitute perlMatch
  213.   " I happen to prefer having matches and substitutions highlighted; if you
  214.   " agree, set the variable "perl_highlight_matches".
  215.   if exists("perl_highlight_matches")
  216.     hi link perlMatch    perlString
  217.   endif
  218.   hi link perlNumber        Number
  219.   hi link perlClassDecl        Typedef
  220.   hi link perlStorageClass    perlType
  221.   hi link perlPackageRef perlType
  222.   hi link perlInclude        Include
  223.   hi link perlControl        PreProc
  224.   hi link perlStatementStorageClass perlStatement
  225.   hi link perlStatementControl      perlStatement
  226.   hi link perlStatementScalar       perlStatement
  227.   hi link perlStatementRegexp       perlStatement
  228.   hi link perlStatementNumeric      perlStatement
  229.   hi link perlStatementList         perlStatement
  230.   hi link perlStatementHash         perlStatement
  231.   hi link perlStatementIOfunc       perlStatement
  232.   hi link perlStatementFixedlength  perlStatement
  233.   hi link perlStatementFiles        perlStatement
  234.   hi link perlStatementFlow         perlStatement
  235.   hi link perlStatementScope        perlStatement
  236.   hi link perlStatementProc         perlStatement
  237.   hi link perlStatementSocket       perlStatement
  238.   hi link perlStatementIPC          perlStatement
  239.   hi link perlStatementNetwork      perlStatement
  240.   hi link perlStatementTime         perlStatement
  241.   hi link perlStatementMisc         perlStatement
  242.   hi link  perlStatement        Statement
  243.   hi link  perlType        Type
  244.   hi link  perlString        String
  245.   hi link  perlPOD            perlComment
  246.   hi link  perlShellCommand     Special
  247.   hi link  perlComment        Comment
  248.   hi link  perlSpecial        Special
  249.   hi link  perlTodo        Todo
  250.   hi link  perlFunction        Function
  251.   hi link  perlIdentifier    Identifier
  252. endif
  253.  
  254. let b:current_syntax = "perl"
  255.  
  256. " vim: ts=8
  257.